N=int(raw_input())
scores = {}
while N>0:
    inputs = raw_input().split(' ')
    teamId = inputs[0].split('-')[0]
    score = int(inputs[1])
    if teamId in scores.keys():
        scores[teamId]+=score
    else:
        scores[teamId]=score
    N-=1

maxTeam, maxScore = '', 0
for k,v in scores.items():
    if maxScore<v:
        maxScore=v
        maxTeam=k
    
print maxTeam+' '+str(maxScore)